/**
 * 
 */
package map;

/**
 * Records of an indexed node list. The list is optimalizied to enable node listing 
 * in a bounds. 
 * 
 * @author balage
 *
 */
public class NodeSlot {

	public static final int WAYTYPE_SEPARATOR = 1000;
	
	//Slot types
	public static final int TYPE_NODE = 0;
	public static final int TYPE_SPLIT_LAT = 1;
	public static final int TYPE_SPLIT_LON = 2;
	public static final int TYPE_LIST = 3;
	public static final int TYPE_WAY = 4;
	
	//Way types
	public static final int WTYPE_UNKNOWN = 0;
	public static final int WTYPE_BOUNDARY = 1;
	public static final int WTYPE_HIGHWAY = 2;
	
	/**
	 * type == 0 -> a node<br>
	 * type == 1 -> split by lat: if (lat < id) ->l1 else ->l2<br>
	 * type == 2 -> split by lon: if (lon < id) ->l1 else ->l2<br>
	 * type == 3 -> unindexed node list<br>
	 * type == 4 -> way section to the next node
	 */
	public byte type = 0;
	
	/**
	 * type == 0 -> id of node<br>
	 * type == 1 -> lat to split<br>
	 * type == 2 -> lon to split<br>
	 * type == 3 -> ref to a node (max long value means null)<br>
	 * type == 4 -> id of way
	 */
	public long id;
	
	/**
	 * type == 0 -> lat of node<br>
	 * type == 1 -> id of slot to go if (lat<id)<br>
	 * type == 2 -> id of slot to go if (lon<id)<br>
	 * type == 3 -> ref to a node (max long value means null)<br>
	 * type == 4 -> type of way (border, highway.. etc) (proposed encoding: pair of ints, meaning type and level)
	 */
	public long l1;
	
	/**
	 * type == 0 -> lon of node<br>
	 * type == 1 -> id of slot to go if (lat>=id)<br>
	 * type == 2 -> id of slot to go if (lon>=id)<br>
	 * type == 3 -> ref to a node (max long value means null)<br>
	 * type == 4 -> ref to node (the other end of this way section)
	 */
	public long l2;
	
	/**
	 * type == 0 -> ref to way section (max long value means null)
	 * type == 1 -> unused
	 * type == 2 -> unused
	 * type == 3 -> ref to a node (max long value means null)
	 * type == 4 -> ref next way section, if more way are connected to the node (max long value means null) 
	 */
	public long w;
	
	@Override
	public String toString() {
		switch(type){
		case TYPE_NODE: return "NODE("+id+"): "+Double.longBitsToDouble(l1)+", "+Double.longBitsToDouble(l2) + " -> "+(w==Long.MAX_VALUE?"null":(""+w));
		case TYPE_SPLIT_LAT: return "SPLIT_LAT: "+Double.longBitsToDouble(id)+" {"+l1+", "+l2+"}";
		case TYPE_SPLIT_LON: return "SPLIT_LON: "+Double.longBitsToDouble(id)+" {"+l1+", "+l2+"}";
		case TYPE_LIST: return "LIST ["+(id==Long.MAX_VALUE?"null":(""+id))+", "+(l1==Long.MAX_VALUE?"null":(""+l1))+", "+(l2==Long.MAX_VALUE?"null":(""+l2))+", "+(w==Long.MAX_VALUE?"null":(""+w))+"]";
		case TYPE_WAY: return "WAY("+id+"):"+l1+" -> "+l2+" -> "+(w==Long.MAX_VALUE?"null":(""+w));
		}
		return super.toString();
	}
	
}
